package com.theme.passport.service.theme.impl;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.theme.common.mvc.utils.PageUtils;
import com.theme.common.mvc.utils.Query;
import com.theme.passport.dao.theme.WidgeConfigDao;
import com.theme.passport.entity.theme.WidgeConfigEntity;
import com.theme.passport.service.theme.WidgeConfigService;
import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Service;

import java.util.Collections;
import java.util.List;
import java.util.Map;


@Service("widgeConfigService")
public class WidgeConfigServiceImpl extends ServiceImpl<WidgeConfigDao, WidgeConfigEntity> implements WidgeConfigService {

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        String widgeId = (String) params.get("widgeId");
        IPage<WidgeConfigEntity> page = this.page(
                new Query<WidgeConfigEntity>().getPage(params),
                new QueryWrapper<WidgeConfigEntity>()
                        .eq(StringUtils.isNotBlank(widgeId), "widge_id", widgeId)
                        .orderByDesc("created")
        );
        return new PageUtils(page);
    }

    @Override
    public WidgeConfigEntity queryInfoByWidgeId(Long widgeId) {
        Wrapper<WidgeConfigEntity> queryWrapper = new QueryWrapper<WidgeConfigEntity>()
                .eq("widge_id", widgeId);
        List<WidgeConfigEntity> widgeConfigEntities = this.baseMapper.selectList(queryWrapper);
        if (widgeConfigEntities != null && widgeConfigEntities.size() > 0){
            return widgeConfigEntities.get(0);
        }
        return null;
    }

    @Override
    public List<WidgeConfigEntity> queryWidgeConfigList(Long widgeId) {
        Wrapper<WidgeConfigEntity> queryWrapper = new QueryWrapper<WidgeConfigEntity>()
                .eq("widge_id", widgeId);
        return this.baseMapper.selectList(queryWrapper);
    }

    @Override
    public List<WidgeConfigEntity> queryWidgeConfigAll(String widge_id) {
        return baseMapper.queryWidgeConfigAll(widge_id);
    }

}